<div id="page-wrapper">
			<div class="box-header">
				<h3 class="box-title">培训评价</h3>

				<div class="box-tools">
					<div class="input-group input-group-sm" style="width: 350px;">
						<input type="text" name="table_search" id="searchNameId"
							class="form-control pull-right" placeholder="用户名">

						<div class="input-group-btn">
							<button type="button" class="btn btn-default btn-search">
                                <i class="fa fa-search"></i>
							</button>
							<button type="button" class="btn btn-default btn-add">评价</button>
							<button type="button" class="btn btn-default btn-update">修改评价</button>
						</div>
					</div>
				</div>
			</div>
			<!-- /.box-header -->
			<div class="box-body table-responsive no-padding">
				<table class="table table-hover">
					<thead>
						<tr>
						 
						    <th></th>
							<th>评分排名</th>
							<th>昵称</th>
							<th>评价内容</th>
							<th>评价时间</th>
							<th>评分</th>
							<th>培训机构名称</th>
						</tr>
					</thead>
					<tbody id="tbodyId">
					    <tr>
					       <td colspan="6">数据正在加载中...</td>
					    </tr>
					</tbody>
				</table>
			</div>
			<div id="pageId" class="box-footer clearfix">
			      
			</div>
			<!-- /.box-body -->
		</div>
		

<script type="text/javascript">
$(function(){
	  $("#pageId").load("doPageUI",function(){
		  doGetObjects();
	  });
	  $(".input-group-btn")
	  .on("click",".btn-search",doQueryObjects)
	  .on("click",".btn-add",doLoadEditUI)
  
	  $("#tbodyId")
	  .on("click",".btn-delete",doDeleteObject)
	  .on("click",".btn-update",doLoadEditUI)
});

function doLoadEditUI(){
	   var title;
	   if($(this).hasClass('btn-add')){
		   title="添加角色";
		   doLoadPageUI(title);
	   }else{
		   title="修改角色"
		   var id=$(this).parents("tr").data("id");
		   var params={"id":id};
		   var url="role/doFindObjectById";
		   $.getJSON(url,params,function(result){
			   if(result.state==1){
				  result.data.id=id;//在结果中动态追加id
				  $("#mainContentId").data("data",result.data);
				  doLoadPageUI(title);//异步加载页面  
			   }else{
				  alert(result.message); 
			   }
		   });
	   }
}
function doLoadPageUI(title){
	   var url="role/role_edit"
	   $("#mainContentId")
	   .load(url,function(){
		   $(".box-title").html(title);
	   })
}



function doDeleteObject(){
	   //1.params
	   var id=$(this).parents("tr").data("id");
	   var params={"id":id};
	   //2.url
	   var url="role/doDeleteObject"
	   //3.ajax request
	   $.post(url,params,function(result){
		   if(result.state==1){
			   alert(result.message);
			   doGetObjects();
		   }else{
			   alert(result.message);
		   }
	   })
	   
}
function doQueryObjects(){
	   $("#pageId").data("pageCurrent",1);
	   doGetObjects();
}
function doGetObjects(){
	debugger;
	   //1.params
	   //获取在Page.html中绑定的当前页码值
	   var pageCurrent=$("#pageId").data("pageCurrent");
	   //假如没有值,设置初始值为1
	   if(!pageCurrent)pageCurrent=1;
	   //var params="pageCurrrent="+pageCurrent;
	   var params={"pageCurrent":pageCurrent};
	   //获取查询时用户输入的名字
	   var name=$("#searchNameId").val();
	   if(name)params.name=name;
	   //2.url
	   var url="agencyComment/findObjects";
	   //3.ajax request
	   
	   console.log(params);
	   $.getJSON(url,params,function(result){
		   doHandleResponseResult(result);
	   });
}
function doHandleResponseResult(result){
	
	   if(result.state==1){
		  doSetTableBodyRows(result.data.records);
		  doSetPagination(result.data);
	   }else{
		  doSetTableBodyErrors(result.message);
	   }
}
function doSetTableBodyErrors(message){
	   //获取body对象并清空
	   var tBody=$("#tbodyId");
	   tBody.empty();
	   //创建tr对象
	   var tr=$("<tr></tr>");
	   //创建td对象
	   //var len=$("table thead").find("tr").find("th").length;
	   var len=$("table th").length;
	   var td=$("<td></td>");
	   td.prop("colspan",len);
	   td.append(message);
	   tr.append(td);
	   //将tr追加到tbody
	   tBody.append(tr);
}
function doSetTableBodyRows(data){
	   debugger;
	  //获取tbody对象,并清空
	   var tBody=$("#tbodyId");
	   tBody.empty();
	   //2.迭代数据,并追加到tBody
		   for(var i in data){
				  var tr=$("<tr></tr>");
				  tr.data("rowData",data[i]);
				  var tds=doCreateTds(data[i]);
				  tr.append(tds);
				  tBody.append(tr);
	   }
}
 
 
  function doCreateTds(row,i){
	   var tds=
		   "<td></td>"+
		   	 "<td>"+row.commentId+"</td>"+
		     "<td>"+row.userId+"</td>"+
		     "<td>"+row.content+"</td>"+
		     "<td>"+row.createtime+"</td>"+
		     "<td>"+row.score+"</td>"+
		     "<td>"+row.agencyId+"</td>";	   
return tds;
 }  
 
</script>
















